import axios from "axios";

// 创建axios实例
const api = axios.create({
  baseURL: window.config.api,
  eout: 100000, // 请求超时时间
  // withCredentials: true
});

// request拦截器
api.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    Promise.reject(error);
  }
);

// response 拦截器
api.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    let code = 0;
    try {
      code = error.response.data.status;
    } catch (e) {
      if (error.toString().indexOf("Error: timeout") !== -1) {
        return Promise.reject(error);
      }
    }
    console.log("req err code == > ", code);
    return Promise.reject(error);
  }
);
export default api;
